//
//  StatusCellTopView.swift
//  Weibo
//
//  Created by 张婷 on 15/10/26.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage


class StatusCellTopView: UIView {
    
    /// 模型数据
    var viewModel: StatusViewModel? {
        didSet {
            nameLabel.text = viewModel?.userScreen_name
            iconView.sd_setImageWithURL(viewModel?.userProfileUrl)
        }
    }
    
    ///  构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 懒加载控件
    /// 头像图片
    private lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
    /// 姓名标签
    private lazy var nameLabel: UILabel = UILabel(title: "MissTing")
    /// 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    /// 认证标志
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_vip")
    /// 时间标签
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", sizeFont: 11)
    /// 来源标签
    private lazy var sourceLabel: UILabel = UILabel(title: "来自 黑马微博", sizeFont: 11)
    
}

// MARK: - 页面设置
extension StatusCellTopView {
    
    // 设置 UI
    private func setupUI() {
        // 0. 背景颜色
        backgroundColor = UIColor.whiteColor()
        
        // 1. 添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 2. 自动布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.width.equalTo(StatusIconWidth)
            make.height.equalTo(StatusIconWidth)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconView.snp_top)
        }
        
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
        }
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(timeLabel.snp_bottom)
        }
        
    
    }

}
